<template>
  <div style="width: 100%; height: 100%; background-color:rgba(255,255,255,0.31); display: flex; flex-direction: column; justify-content: center; align-items: center">
    <h1 style="color: #fff; margin-bottom: 40px">微信登录中</h1>
    <a-spin :spinning="true" style="width: 50px; height: 50px;"></a-spin>
  </div>
</template>

<script>
import { getOauth2UserInfo } from '@/api/login'

export default {
  name: 'Oauth2Login',
  computed: {
    code () {
      return this.$route.query.code
    },
    state () {
      return this.$route.query.state
    }
  },
  created () {
    getOauth2UserInfo({ code: this.code }).then(res => {
      // TODO
      if (res.success) {
        this.$message.success(res.result)
        // 跳转至主页
      } else {
        this.$message.success(res.message)
        // 跳转至完善用户信息页面
      }
    }).catch(err => {
      this.$notification['error']({
        message: '错误',
        description: ((err.response || {}).data || {}).message || '请求出现错误，请稍后再试'
      })
      this.$router.push({ name: 'login' })
    })
  }
}
</script>

<style scoped>

</style>
